package com.fh.modules.kms.service.impl;

/**
 * @Author qiujunda
 * @Date 15/06/2020
 * @Description
 */
//@Service
public class SqlLogServiceImpl /* implements SqlLogService*/ {
/*
    @Autowired
    private ElasticsearchRestTemplate elasticsearchTemplate;
    @Autowired
    private SqlLogRepository sqlLogRepository;

    private Pageable pageable = PageRequest.of(0,10);

    @Override
    public void createIndex() {
        elasticsearchTemplate.createIndex(SqlLog.class);
    }

    @Override
    public void deleteIndex(String index) {
        elasticsearchTemplate.deleteIndex(index);
    }

    @Override
    public void save(SqlLog docBean) {
        sqlLogRepository.save(docBean);
    }

    @Override
    public void saveAll(List<SqlLog> list) {
        sqlLogRepository.saveAll(list);
    }

    @Override
    public Iterator<SqlLog> findAll() {
        return sqlLogRepository.findAll().iterator();
    }

    @Override
    public Page<SqlLog> queryForPage(SqlLogVo sqlLogVo) {
        SortBuilder sortBuilder = SortBuilders.fieldSort("requestBeginTime").order(SortOrder.DESC);
        SortBuilder sortBuilder2 = SortBuilders.scoreSort().order(SortOrder.DESC);
        PageRequest pageable = PageRequest.of(sqlLogVo.getPageNo(),sqlLogVo.getPageSize());
        BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();

        SqlLog sqlLog=sqlLogVo.getSqlLog();
        if(sqlLog==null){
            sqlLog=new SqlLog();
        }
        String indexName=sqlLogVo.getIndexName();
        if(!StringUtils.isEmpty(indexName)){
            boolQueryBuilder.must(QueryBuilders.matchQuery("dbName", indexName));
        }
        String actor=sqlLog.getActor();
        if(!StringUtils.isEmpty(actor)){
            boolQueryBuilder.must(QueryBuilders.termQuery("actor", actor));
        }
        Long requestTime=sqlLog.getRequestTime();
        if(requestTime!=null&&requestTime>0){
            boolQueryBuilder.must(QueryBuilders.rangeQuery("requestTime").gte(requestTime));
        }
        Date requestBeginTime=sqlLog.getRequestBeginTime();
        if(requestBeginTime!=null){
            boolQueryBuilder.must(QueryBuilders.rangeQuery("requestBeginTime").gte(requestBeginTime.getTime()));
        }
        Date requestEndTime=sqlLog.getRequestEndTime();
        if(requestEndTime!=null){
            boolQueryBuilder.must(QueryBuilders.rangeQuery("requestBeginTime").lte(requestEndTime.getTime()));
        }
        String clusterNode=sqlLog.getClusterNode();
        if(!StringUtils.isEmpty(clusterNode)){
            boolQueryBuilder.must(QueryBuilders.termQuery("clusterNode", clusterNode));
        }
        String logType=sqlLog.getLogType();
        if(!StringUtils.isEmpty(logType)){
            boolQueryBuilder.must(QueryBuilders.matchQuery("logType", logType));
        }
        String requestUrl=sqlLog.getRequestUrl();
        if(!StringUtils.isEmpty(requestUrl)){
            boolQueryBuilder.must(QueryBuilders.matchQuery("requestUrl", requestUrl));
        }
        String sessionId=sqlLog.getSessionId();
        if(!StringUtils.isEmpty(sessionId)){
            boolQueryBuilder.must(QueryBuilders.termQuery("sessionId", sessionId));
        }
        String sql=sqlLog.getSql();
        if(!StringUtils.isEmpty(sql)){
            boolQueryBuilder.must(QueryBuilders.matchQuery("sql", sql));
        }
        SearchQuery searchQuery = new NativeSearchQueryBuilder()
                .withQuery(boolQueryBuilder).withSort(sortBuilder2).withSort(sortBuilder).withPageable(pageable)
                .build();
        return elasticsearchTemplate.queryForPage(searchQuery, SqlLog.class);
//        return sqlLogRepository.search(boolQueryBuilder,pageable);
    }

    @Override
    public Object queryAggregationForPage() {
        return null;
    }*/
}
